package com.sdry.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sdry.system.entity.SysRole;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * @program: info_sdry
 * @description: 角色管理
 * @author: cb
 * @create: 2020-02-12 19:58
 **/
public interface RoleMapper extends BaseMapper<SysRole> {

    /**
     * 添加到角色菜单表
     * @param roleId
     * @param menuId
     */
    @Insert("insert into sys_role_menu(role_id,menu_id) VALUES (#{roleId},#{menuId})")
    void addRoleMenu(@Param("roleId") Long roleId, @Param("menuId") String menuId);

    /**
     * 添加到角色App菜单表
     * @param roleId
     * @param menuId
     */
    @Insert("insert into sys_role_app_menu(role_id,menu_id) VALUES (#{roleId},#{menuId})")
    void addRoleAppMenu(@Param("roleId") Long roleId, @Param("menuId") String menuId);

    /**
     * 角色删除
     * @param roleId
     */
    @Delete("delete from sys_role_menu where  role_id = #{roleId}")
    void deleteRoleMenu(Long roleId);


    /**
     * app角色删除
     * @param roleId
     * @return Integer
     */
    @Delete("delete from sys_role_app_menu where  role_id = #{roleId}")
    Integer deleteRoleAppMenu(Long roleId);

    /**
     * 删除角色（实际是字段更新）
     * @param roleId
     * @param userId
     * @return
     */
    @Update("update sys_role set del_flag = '1', update_date = getDate() ,update_by = #{userId}  where role_id = #{roleId}")
    Integer deleteRole(@Param("roleId") Long roleId, @Param("userId") Long userId);

    /**
     * 当前角色对应的菜单
     * @param roleId
     * @return
     */
    @Select("select menu_id from sys_role_menu where role_id = #{roleId}")
    List<Long> queryRoleMenuList(Long roleId);

    /**
     * 当前角色对应的app菜单
     * @param roleId
     * @return
     */
    @Select("select menu_id from sys_role_app_menu where role_id = #{roleId}")
    List<Long> queryAppRoleMenuList(Long roleId);

}
